package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.product.entity.BaseTrademark;
import com.atguigu.gmall.product.service.BaseTrademarkService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/admin/product")
public class BaseTrademarkController {
    @Autowired
    BaseTrademarkService baseTrademarkService;
    /**
     * 查询品牌分页数据
     * @param pn
     * @param ps
     * @return
     */
    @ApiOperation("分页查询")
    @GetMapping("/baseTrademark/{pn}/{ps}")
    public Result baseTrademarkList(@PathVariable("pn") Long pn,
                                    @PathVariable("ps") Long ps){

        Page<BaseTrademark> page = new Page<>(pn,ps);
        //分页查询；  需要引入分页插件
        Page<BaseTrademark> result = baseTrademarkService.page(page);
        return Result.ok(result);
    }
    /**
     * 保存品牌
     * @param baseTrademark
     * @return
     */
    @ApiOperation("保存品牌")
    @PostMapping("/baseTrademark/save")
    public Result save(@RequestBody BaseTrademark baseTrademark){
        baseTrademarkService.save(baseTrademark);
        return Result.ok();
    }
    /**
     * 删除
     * @return
     */
    @ApiOperation("删除数据")
    @DeleteMapping("/baseTrademark/remove/{id}")
    public Result delete(@PathVariable("id")Long id){
        baseTrademarkService.removeById(id);
        return Result.ok();
    }
    /**
     * 修改-回显查询
     * @param id
     * @return
     */
    @ApiOperation("修改前数据回显")
    @GetMapping("/baseTrademark/get/{id}")
    public Result get(@PathVariable("id")Long id){
        BaseTrademark baseTrademark = baseTrademarkService.getById(id);
        return Result.ok(baseTrademark);
    }
    /**
     * 修改-修改
     * @return
     */
    @ApiOperation("修改品牌")
    @PutMapping("/baseTrademark/update")
    public Result update(@RequestBody BaseTrademark  trademark){
        baseTrademarkService.updateById(trademark);
        return Result.ok();
    }

    /**
     * 获取品牌属性
     * @return
     */
    @GetMapping("/baseTrademark/getTrademarkList")
    public Result getTrademarkList(){
        List<BaseTrademark> list = baseTrademarkService.list();
        return Result.ok(list);
    }
}
